iT邦幫忙

2023 iThome 鐵人賽

DAY 12
0
自我挑戰組

TypeScript 從0開始系列 第 12

D12 - Todo list with React

  • 分享至 

  • xImage
  •  
import React, { useState } from "react";
import TodoList from "./TodoList";

// react manages states in app => state chages, then re-render
// hook: 
//     useState: return an array, specifically, [array, function]
 
function App() {
  // * Object destructuring
  const [todos, setTodos] = useState(["todo 1", "todo 2"])
  //                                 ^^^^^^^^^^^^^^^^^^^^ initial state of todos 
  //            ^^^^^^^ function to update `todos`
  //     ^^^^^ array that return by useState()
  return (
    <>
    
      <TodoList todos={ todos } />
      {/* every components has `props` */}
      <input type="text" />
      <input type="button" value="Add Todo" />
      <input type="button" value="Clear Completed" />
      <p>0 left to do</p>
    </>
  );
}

export default App;


上一篇
D11 - Todo list with typescript
下一篇
D13 - Todo list with React (2)
系列文
TypeScript 從0開始21
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言